package com.siashan.toolkit.lock4j;

import org.redisson.Redisson;
import org.redisson.api.RedissonClient;
import org.redisson.spring.starter.RedissonAutoConfiguration;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.AutoConfigureAfter;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * Redisson锁自动配置器
 *
 * @author siashan
 * @since v1.0.1
 */
@Configuration
@ConditionalOnClass(Redisson.class)
@AutoConfigureAfter({RedissonAutoConfiguration.class,Lock4jAutoConfiguration.class})
class RedissonLockAutoConfiguration {

    @Autowired
    private LockTemplate lockTemplate;

    @Bean
    @ConditionalOnMissingBean
    public RedissonLockExecutor redissonLockExecutor(RedissonClient redissonClient) {
        RedissonLockExecutor redissonLockExecutor = new RedissonLockExecutor(redissonClient);
        lockTemplate.setLockExecutor(redissonLockExecutor);
        return redissonLockExecutor;
    }
}